/*
 ** StockDB
 **
 ** Copyright (C) 2012 - ? doublegsoft
 **
 ** This program is free software: you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation, either version 3 of the License, or
 ** (at your option) any later version.
 **
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 **
 ** You should have received a copy of the GNU General Public License
 ** along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <stdio.h>
#include <string.h>

#include "storage.h"

int
main()
{
  const char *dir = ".";
  const char *name = "test";
  // create database
  printf("################################################################\n");
  printf("#                       Create Database                        #\n");
  printf("################################################################\n");
  stockdb_create_database(dir, name);
  printf("the database \"%s\" is created.\n", name);
  // append stock information
  printf("################################################################\n");
  printf("#                        Append Stocks                         #\n");
  printf("################################################################\n");
  stock_t stock;
  strcpy(stock.code, "100001");
  stock.first = 0;
  stock.last = 0;
  stock.size = 0;
  stock.next = 0;
  stockdb_append_stock(dir, name, &stock);
  printf("the stock \"%s\" is added.\n", "100001");
  strcpy(stock.code, "100002");
  stock.first = 0;
  stock.last = 0;
  stock.size = 0;
  stock.next = 0;
  stockdb_append_stock(dir, name, &stock);
  printf("the stock \"%s\" is added.\n", "100002");
  strcpy(stock.code, "100003");
  stock.first = 0;
  stock.last = 0;
  stock.size = 0;
  stock.next = 0;
  stockdb_append_stock(dir, name, &stock);
  printf("the stock \"%s\" is added.\n", "100003");
  printf("################################################################\n");
  printf("#               Append Stock '100001' Daily Data               #\n");
  printf("################################################################\n");
  stock_daily_t daily;
  daily.time = 20120416L;
  daily.open = 10880L;
  daily.high = 10990L;
  daily.low = 10760L;
  daily.closed = 10880L;
  daily.volume = 20000L;
  daily.amount = 2188000L;
  daily.next = 0;
  stockdb_append_stock_daily(dir, name, "100001", &daily);
  daily.time = 20120417L;
  daily.open = 10880L;
  daily.high = 10990L;
  daily.low = 10760L;
  daily.closed = 10880L;
  daily.volume = 20000L;
  daily.amount = 2188000L;
  daily.next = 0;
  stockdb_append_stock_daily(dir, name, "100001", &daily);
  daily.time = 20120418L;
  daily.open = 10880L;
  daily.high = 10990L;
  daily.low = 10760L;
  daily.closed = 10880L;
  daily.volume = 20000L;
  daily.amount = 2188000L;
  daily.next = 0;
  stockdb_append_stock_daily(dir, name, "100001", &daily);
}

